package Assignment;

import Code.Test.Test1;

/*
需求：定义一个方法copyOfRange(int[] arr,int from, int to)
功能：将数组arr中从索引from（包含from）开始，到索引to结束（不包含to）的元素复制到新数组中，并将新数组返回。
 */
public class Test10 {
    public static void main(String[] args) {
        int[] arr = {1,2,3,4,5,6};
        int[] newArr = copyOfRange(arr,1,6);

        //遍历数组
        Test1.Traversal(newArr);


    }
    public static int[] copyOfRange(int[] arr,int from, int to){
        int[] newArr = new int[to - from];

        int index = 0;
        for (int i = from; i < to; i++) {
            newArr[index] = arr[i];
            index++;
        }
        return newArr;
    }
}
